<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>登录页面</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
	<script src="/js/jquery/jquery.min.js"></script>
	<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
	<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" >
	<link rel="stylesheet" href="/css/reset.css" >
	<link rel="stylesheet" href="/css/login.css" >
	<link rel="stylesheet" href="js/plugins/dialog2/dialog.css">
	<script src="js/plugins/dialog2/dialog.min.js"></script>
	<script src="js/plugins/form/jquery.form.js"></script>

</head>
<body>
<div class="container" >
	<h5>登录</h5>

	<div class="card card-container ">
		<i id="profile-img" class="fa fa-user-circle fa-5x profile-img" ></i>
		<form class="form-signin" id="loginForm" action="/sessions" method="post">
			<input type="email"  name="email" value="chenhui@wolfcode.cn" class="form-control badge-pill" placeholder="邮箱"  >
			<input type="password"  name="password" value="1" class="form-control badge-pill" placeholder="密码" >
			<a href="#" class="forgot-password">
				忘记密码？
			</a>
			<button class="btn btn-lg badge-pill" type="submit" >登录</button>
		</form>
	</div>


	<a href="register.html" class="registerLink" >
		新用户？点击这里注册
	</a>
</div>
<script>
	$(function () {
		$("#loginForm").ajaxForm(function (data) {

            if (data.success) {
                //登录成功,跳转进首页
                //把当前登录用户存储到sessionStorage ,sessionStorage只能存储字符串
                //设置进去之前,先把对象转为json字符串
				sessionStorage.setItem("user",JSON.stringify(data.result));//在登录页面拿到登录用户的信息,只能共享字符串
                console.log(data.result);
                console.log(JSON.stringify(data.result));//转化为json字符串
                //parent如果有父窗口就会指向父窗口,如果没有就还是window自己
                window.parent.location.href = "/index.html";
            }else{
                //登录失败
                $(document).dialog({
                    titleShow: false,
                    content: data.msg
                });
			}
        });
    });
</script>
</body>
</html>
